<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改密码</title>
    <%- include common %>
</head>
<body>
    <%- include("head",{title:"changepass",username:username})%>
    <div class="container container-fluid">
        <div class="row" >
            <div class="col-md-4 col-lg-4 col-sm-4">
                <h2 class="text-primary">修改密码</h2>
                <form >
                    <div class="form-group">
                        <label for="oldpass">旧密码</label>
                        <input id="oldpass"  type="text" class="form-control" placeholder="请输入用户名">
                    </div>
                    <div class="form-group">
                        <label for="newpass">新密码</label>
                        <input id="newpass"  type="password" class="form-control" placeholder="请输入密码">
                    </div>
                    <div class="form-group">
                        <label for="confirmnewpass">确认新密码</label>
                        <input id="confirmnewpass"  type="password" class="form-control" placeholder="请输入密码">
                    </div>
                    <div class="form-group">
                        <a href="/" class="link">忘记密码,找回密码-联系月月鸟</a>  
                    </div>
                    <div class="form-group">
                        <button type="button" data-username="<%- username %>" id="changebtn" class="btn btn-success">修改密码</button>
                        <button type="reset" class="btn btn-danger">重置</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <%- include foot %>
    <script>
        $("#changebtn").click(function(){
            $.ajax({
                url:"/users/changepass",
                method:"POST",
                data:{
                    oldpass:$("#oldpass").val(),
                    newpass:$("#newpass").val(),
                    username:$("#changebtn").attr("data-username")
                },
                success(res){
                    console.log(res);
                    if(res.code==200){
                        if(res.type){
                            window.location.href = "/login"
                        }
                        alert(res.msg);
                    }
                }
            })
        })
    </script>
</body>
</html>